package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.BpDeviceFacilityCheckRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.Date;

public interface BpDeviceFacilityCheckRecordDao extends JpaRepository<BpDeviceFacilityCheckRecord,Long>, QuerydslPredicateExecutor<BpDeviceFacilityCheckRecord> {
    public Page<BpDeviceFacilityCheckRecord> findAll(Specification<BpDeviceFacilityCheckRecord> spec, Pageable pageable);


    @Query(value = "select count(*) from wwyt_bp_device_facility_check_record where id != ?1 and device_facility_id = ?2 and check_validity_date >= ?3 and delete_flag = '0' ",nativeQuery = true)
    Long isLastRecord(Long id, Long deviceFacilityId, Date detectDate);
}
